﻿Imports Control_Vuelos_BL
Imports DevExpress.XtraGrid.Views.Grid

Public Class frmSegPerfiles
    Inherits frmBaseMantenimiento

    Private ReadOnly oPerfiles As New MaestrosBL()
    Private ReadOnly oPerfilesMenu As New Perfil_MenuBL()

    Private Sub frmSegPerfiles_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        prl_Refresh()
        AddHandler UcPerfiles1.GridView1.FocusedRowChanged, AddressOf prl_FocusedFila
        AddHandler UcPerfiles1.cmdLoadmenu.Click, AddressOf prl_Loadmenu
        AddHandler BarBtnAgregar.ItemClick, AddressOf prl_Nuevo
        AddHandler UcPerfiles1.cmdGrabar.Click, AddressOf prl_GrabarMenuPerfil
        UcPerfiles1.LClItemGrabarPerfil.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
        UcPerfiles1.LClItemTreeList.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
        Dim grid As GridView = CType(UcPerfiles1.GridView1, GridView)
        If grid.RowCount > 0 Then
            Dim row As DataRow = TryCast(grid.GetDataRow(grid.GetSelectedRows()(0)), DataRow)
            If Not row Is Nothing Then
                UcPerfiles1.gnomuser.EditValue = row("desnive")
            End If
        End If
    End Sub

    Public Sub prl_GrabarMenuPerfil()
        Dim GridData As DataTable = CType(UcPerfiles1.TreeList1.DataSource, DataTable)
        ' Prueba de cambios
    End Sub

    Public Sub prl_Nuevo()
        Dim oDialogResult As System.Windows.Forms.DialogResult
        Using sfrmPerfil As New frmSegPerfilesMantenimiento() With {.Text = "Pefiles (AGREGAR)"}
            oDialogResult = sfrmPerfil.ShowDialog()
            If oDialogResult = Windows.Forms.DialogResult.OK Then
                prl_Refresh()
            End If
        End Using
    End Sub

    Private Sub prl_Refresh()
        UcPerfiles1.GridControl1.DataSource = oPerfiles.pr_GetPerfiles()
    End Sub

    Public Sub prl_Loadmenu(sender As System.Object, e As System.EventArgs)
        Dim grid As GridView = CType(UcPerfiles1.GridView1, GridView)
        If grid.RowCount > 0 Then
            Dim row As DataRow = TryCast(grid.GetDataRow(grid.GetSelectedRows()(0)), DataRow)
            If Not row Is Nothing Then
                UcPerfiles1.TreeList1.DataSource = oPerfilesMenu.pr_Get_PerfilMenu(row("codnive"))
                UcPerfiles1.TreeList1.ExpandAll()
                UcPerfiles1.TreeList1.FocusedNode = UcPerfiles1.TreeList1.Nodes.FirstNode
                UcPerfiles1.LClItemGrabarPerfil.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
                UcPerfiles1.LClItemTreeList.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
            End If
        End If
    End Sub

    Public Sub prl_FocusedFila(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs)
        Dim grid As GridView = CType(sender, GridView)
        If grid.RowCount > 0 Then
            Dim row As DataRow = TryCast(grid.GetDataRow(grid.GetSelectedRows()(0)), DataRow)
            If Not row Is Nothing Then
                UcPerfiles1.LClItemGrabarPerfil.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
                UcPerfiles1.LClItemTreeList.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
                UcPerfiles1.gnomuser.EditValue = row("desnive")
            End If
        End If
    End Sub
End Class